<template>
    <div id="content">
        <div class="page-header">
            <div class="container-fluid">
                <div class="pull-right">
                    <a href="#/catalog/category/create" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="添加"><i class="fa fa-plus"></i></a> <a href="https://mall.opencart.cn/admin/index.php?route=catalog/category/repair&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="重建"><i class="fa fa-refresh"></i></a>
                    <!--<button type="button"-->
                            <!--v-on:click="category_remove()"-->
                            <!--class="btn btn-danger" data-original-title="删除">-->
                        <!--<i class="fa fa-trash-o"></i>-->
                    <!--</button>-->
                </div>
                <h1>商品分类</h1>
                <ul class="breadcrumb">
                    <li><a href="https://mall.opencart.cn/admin/index.php?route=common/dashboard&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2">首页</a></li>
                    <li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2">商品分类</a></li>
                </ul>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row">
                <div id="filter-product" class="col-md-3 col-md-push-9 col-sm-12 hidden-sm hidden-xs">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-filter"></i> 筛选过滤</h3>
                        </div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label class="control-label" for="input-name">分类名称</label>
                                <input type="text" name="filter_name" value="" placeholder="分类名称" id="input-name" class="form-control">
                            </div>
                            <div class="form-group">
                                <label class="control-label" for="input-status">状态</label> <select name="filter_status" id="input-status" class="form-control">
                                <option value=""></option>
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                            </select>
                            </div>
                            <div class="form-group text-right">
                                <button type="button" id="button-filter" class="btn btn-default"><i class="fa fa-filter"></i> 筛选</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-9 col-md-pull-3 col-sm-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h3 class="panel-title"><i class="fa fa-list"></i> 商品分类列表</h3>
                        </div>
                        <div class="panel-body">
                            <form action="https://mall.opencart.cn/admin/index.php?route=catalog/category/delete&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2" method="post" enctype="multipart/form-data" id="form-category">
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <td style="width: 1px;" class="text-center">
                                                <input type="checkbox" onclick="$('input[name*=\'selected\']').trigger('click');"></td>
                                            <td class="text-left">
                                                <a href="" class="asc">分类名称</a>
                                            </td>
                                            <td class="text-right">
                                                <a href="">排序</a>
                                            </td>
                                            <td class="text-right">状态</td>
                                            <td class="text-right">编辑分类</td>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="item in category_list">
                                            <td class="text-center">
                                                <input type="checkbox"  v-model="selected_categoty" name="selected[]" v-bind:value="item.id">
                                            </td>
                                            <td class="text-left">{{item.cat_name}}</td>
                                            <td class="text-right">{{item.sort_order}}</td>
                                            <td class="text-right">
                                                <span v-show="item.status==1">启用</span>
                                                <span v-show="item.status==0">禁用</span>
                                            </td>
                                            <td class="text-right">
                                                <a v-bind:href="'#/catalog/category/edit/' + item.id " data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="编辑">
                                                    <i class="fa fa-pencil"></i></a>
                                                <!--<a href="" target="_blank" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="查看">-->
                                                    <!--<i class="fa fa-search"></i></a>-->
                                                <a  v-on:click="category_remove( item )"
                                                        class="btn btn-danger" data-original-title="删除">
                                                    <i class="fa fa-trash-o"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </form>
                            <div class="row">
                                <div class="col-sm-6 text-left"><ul class="pagination"><li class="active"><span>1</span></li><li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2&amp;page=2">2</a></li><li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2&amp;page=3">3</a></li><li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2&amp;page=4">4</a></li><li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2&amp;page=2">&gt;</a></li><li><a href="https://mall.opencart.cn/admin/index.php?route=catalog/category&amp;user_token=9dd7a9d37c8d6f052a0cab1a812782d2&amp;page=4">&gt;|</a></li></ul></div>
                                <div class="col-sm-6 text-right">显示 1 - 20 / 合计 72（共 4 页）</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>

    export default {
        name: "category",

        data:function(){

            return {

                selected_categoty:[],

                category_list:[]

            }


        },

        methods:{

            get_list:function(){

                var t = this;
                // var url = this.config.web_url + '/admin.php?r=category';
                var url = this.config.web_url + '&r=category.index';
                this.axios.get( url ).then(function( res ){

                    t.category_list = res.data
                });

            },

            category_remove : function( category ){

                var t = this;

                // var url = this.config.web_url + '/admin.php?r=category/remove';
                var url = this.config.web_url + '&r=category.remove';

                var data = 'category_id=' + category.id;
                // for( var p in this.selected_categoty ){
                //     data += 'categories[]=' + this.selected_categoty[p] + '&';
                //
                // }

                this.axios.post( url, data ).then(function( res ){

                    if( res.data.status == 0 ){
                        t.get_list();
                    }else{
                        alert( res.data.description );
                    }

                });

            }

        },

        created:function(){

            this.get_list();
        }

    }
</script>

<style scoped>

</style>